export function utcToDate (timestamp) {
  timestamp = timestamp * 1000
  let y:any = new Date(timestamp).getFullYear(),
      m:any = new Date(timestamp).getMonth() + 1,
      d:any = new Date(timestamp).getDate(),
      h:any = new Date(timestamp).getHours(),
      mm:any = new Date(timestamp).getMinutes()
  const m0 = m
  m = m < 10 ? '0' + m : m
  mm = mm < 10 ? '0' + mm : mm
  h = h < 10 ? '0' + h : h
  return y + '年' + m0 + '月' + d + '日 ' + h + ':' + mm
}

export function loadMore({
  el = '',
  cb = function() {}
}) {
  this.el = el;
  this.cb = cb;
  this.loading = false;
  loadMore.prototype.toEnd = function() {
      // documen.body.scrollTop在chomre下居然一直为0！
      var scrollTop = this.el ? this.el.scrollTop : window.scrollY,
          pageHeight = this.el ? this.el.getBoundingClientRect().height : window.innerHeight,
          scrollHeight = this.el ? this.el.scrollHeight : document.body.scrollHeight;
      if (scrollTop + pageHeight > scrollHeight - 5) {
          if (this.loading) return;
          this.loading = true;
          this.cb();
      }
  }
  loadMore.prototype.open = function() {
      this.listener = this.toEnd.bind(this);
      this.el ? this.el.addEventListener('scroll', this.listener, false) : window.addEventListener('scroll', this.listener, false);
  }
  loadMore.prototype.close = function() {
      this.el ? this.el.removeEventListener('scroll', this.listener, false) : window.removeEventListener('scroll', this.listener, false);
  }
}
